function getLastRateDate(){
	var lastRateDate=null;
	for each (var rateNode in document.children){
		if(rateNode.qnamePath.indexOf(person.properties.userName+"__likesRatingScheme")==-1)
			continue;
		if(lastRateDate==null||rateNode.properties["cm:ratedAt"].getTime()>lastRateDate.getTime())
			lastRateDate=rateNode.properties["cm:ratedAt"];
	}
	return lastRateDate;
}

function getLastVersionDate() {
	var lastVersionDate=null;
	for each (var versionNode in document.versionHistory){
		if(lastVersionDate==null||versionNode.createdDate.getTime()>lastVersionDate.getTime())
			lastVersionDate=versionNode.createdDate;
	}
	return lastVersionDate;
}

var data ='{ title: "'+document.name+'",page:"dlitem-details?nodeRef='+document.nodeRef+'"}';
var lastRateDate=getLastRateDate();
var lastVersionDate=getLastVersionDate();

if(lastRateDate==null||lastVersionDate>lastRateDate.getTime()){

	//avoid to register not likes
	var dateNow=new Date();
	if(dateNow.getTime()-lastVersionDate.getTime()<1500){
		if(document.versionHistory.length==1) {
			activities.postActivity("org.alfresco.csr.csr-created", space.parent.parent.name, "csr",data);
		}else {
			activities.postActivity("org.alfresco.csr.csr-updated", space.parent.parent.name, "csr",data);
		}
	}else{
		//logFile.content += "\ndo nothing - it's an unlike";
	}
} else {
	activities.postActivity("org.alfresco.csr.csr-liked", space.parent.parent.name, "csr",data);
}
